package com.wjjun.basemvpvm.databinding.adapter;

import android.databinding.BindingAdapter;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SimpleItemAnimator;

/**
 * RecyclerViewAdapter
 */
public class RecyclerViewAdapter {

    @BindingAdapter("showAnimator")
    public static void setAnimator(RecyclerView recyclerView, boolean showAnimator) {
        if (recyclerView.getItemAnimator() != null) {
            recyclerView.getItemAnimator().setAddDuration(0);
            recyclerView.getItemAnimator().setMoveDuration(0);
            recyclerView.getItemAnimator().setChangeDuration(0);
            recyclerView.getItemAnimator().setRemoveDuration(0);
            if (recyclerView.getItemAnimator() instanceof SimpleItemAnimator) {
                ((SimpleItemAnimator) recyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
            }
            recyclerView.setItemAnimator(null);
        }
    }

    @BindingAdapter("nestedScrollingEnabled")
    public static void setNestedScrollingEnabled(RecyclerView recyclerView, boolean nestedScrollingEnabled) {
        recyclerView.setNestedScrollingEnabled(nestedScrollingEnabled);
    }

}
